package models

import (
	"192.168.1.75/go-pkg/helper"
	"gorm.io/gorm"
)

// FloorPath 楼层路径
type FloorPath struct {
	ID        string `json:"id" gorm:"column:id;primaryKey;type:int;size:64;comment:主键id"`
	FloorID   string `json:"floor_id" gorm:"column:floor_id;type:int;size:64;comment:楼层id"`
	Name      string `json:"name" gorm:"column:name;type:string;size:40;comment:路径名称"`
	Path      string `json:"path" gorm:"column:path;type:text;size:2000;comment:导航路径,格式 x1:y1,x2:y2"`
	CreatedAt int64  `json:"created_at,omitempty" gorm:"column:created_at;autoCreateTime;type:int;size:64;comment:创建时间"`
	UpdatedAt int64  `json:"updated_at,omitempty" gorm:"column:updated_at;autoUpdateTime;type:int;size:64;comment:更新时间"`
}

// TableName 表名
func (FloorPath) TableName() string {
	return "floor_path"
}

// BeforeCreate 自增id
func (l *FloorPath) BeforeCreate(tx *gorm.DB) (err error) {
	if l.ID != "" {
		return nil
	}
	// 用户id为空时，自动添加用户id
	uuid, err := helper.UUID{}.String()
	if err != nil {
		return err
	}
	l.ID = uuid
	return nil
}

// 模式自动注册
func init() {
	Models = append(Models, &FloorPath{})
}
